package scau.erps.view.dashboard;

import java.awt.Font;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import scau.erps.app.Erps;
import scau.erps.entity.Balancesheet;
import scau.erps.service.BalancesheetService;
import scau.erps.service.impl.BalancesheetServiceImpl;

/**
 * 所有者权益柱状图 * 
 * @author outsider
 */
public class TotalEquityChart {
	/**
	 * 得到图片
	 * 
	 */
	public static JFreeChart getChart() {
		JFreeChart chart = createChart(createDataset());
		return chart;
	}

	/**
	 * 数据
	 */
	private static CategoryDataset createDataset() {
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		BalancesheetService balancesheetService=Erps.getIocInstance().get(BalancesheetServiceImpl.class);		
		List<Balancesheet> list=balancesheetService.getBalancesheetByTeamid(Erps.getCurrentTeam().getId());
		
		
		for (Balancesheet balancesheet : list){
			if (balancesheet.getYear().equals("Y8")==false)           //Y8数据等价Y-1 不存在
			dataset.setValue(balancesheet.getTotalEquity(), "", balancesheet.getYear());
		}
		return dataset;
	}

	/**
	 * 绘制折线
	 */
	private static JFreeChart createChart(CategoryDataset dataset) {
		JFreeChart jfreeChart = ChartFactory.createBarChart3D("公司所有者权益","年份", "总额", dataset, PlotOrientation.VERTICAL, true, false,false);
		jfreeChart.setTitle(new TextTitle("公司所有者权益", new Font("宋体", Font.BOLD + Font.ITALIC, 20)));
		CategoryPlot plot = (CategoryPlot) jfreeChart.getPlot();
		CategoryAxis categoryAxis = plot.getDomainAxis();
		categoryAxis.setLabelFont(new Font("仿宋", Font.ROMAN_BASELINE, 12));
		return jfreeChart;
	}
}
